package lidardatabase;


import java.io.*;
import java.util.Scanner;
import java.sql.*;
/* Dumps a file into a PostGIS database
 * 
 * */

public class FileDumper {
	
	
	private String filename;
	private PostgresDatabaseConnection conn;
	private PreparedStatement insert;
	
	private final String TABLE_NAME = "Points";
	private final String INSERT_STATEMENT = "INSERT INTO " + 
				TABLE_NAME + " (point_geom, tile_id, intensity) VALUES (GeomFromText(\"POINT(? ? ?)\"), ?, ?)";
	
	
	public FileDumper(String filename, PostgresDatabaseConnection c){
		
		this.filename = filename;
		this.conn = c;
		
		try{
			insert = conn.prepareStatement(INSERT_STATEMENT);
		}catch(SQLException e){
			System.err.println("Can't use connection object; reason" + e.getMessage());
			e.printStackTrace();
		}
	}
	
	public void processFile(){
		
		Scanner s = null;
		try{
			s = new Scanner(new BufferedReader(new FileReader(filename)));
			double x, y, z, i;
			while(s.hasNext()){
				x = s.nextDouble();
				y = s.nextDouble();
				z = s.nextDouble();
				i = s.nextDouble();
				
				
			}
			
		}catch(Exception e){
			System.err.println(e.getMessage());
			e.printStackTrace();
		}finally{
			if (s != null){
				s.close();
			}
		}
	}
}
